from google.appengine.ext import db

from models.Topics import *
from models.Messages import *

from google.appengine.ext.db import djangoforms
# from models.Topics import *

class Group(db.Model):
  """This will serve as the highest level organization for messages
  and discussions and such. This will allow people to have their 
  discussions grouped by class, project, ect. has one-to-many relation
  with topics
  
  The arguments inside the parenthesis give us model level validation 
  to ensure that an object can not be created without these properties. """
  title = db.StringProperty(required=True, multiline=False)
  date_created = db.DateTimeProperty(required=True, auto_now_add=True)
  author = db.IntegerProperty(required=True,default=1)
  
  # a list of email addresses that will be the moderators for specific group
  moderators = db.ListProperty(str, required=True, default=[])
  
  def delete(self):
    """Overriding the default delete method so that we delete all other
     entities associated with the group. So we will recursivly delete all 
     Topics and all Messages """
    
    # fetch all the associated topics
    # query = Topic.all()
    #     query.filter("group_id = ", self.key().id())
    #     
    #     # iterate through all topics to delete them
    #     for item in query:
    #       item.delete()
    
    # now delete the group entity itself by calling the base class delete
    db.Model.delete(self)

class GroupForm(djangoforms.ModelForm):
    class Meta:
        model = Group
        exclude = ['_class','author','moderators']
